
#include        <stdlib.h>
#include        "my.h"


void            my_showtab(char **tab)
{
  int           i;

  i = 0;
  while (tab[i] != '\0')
    {
      my_putstr(tab[i++]);
      my_putchar('\n');
    }

}

int             check_oper(char c)
{
  if (c == '+' || c == '-' || c == '%' || c == '*' || c == '/')
    return (1);
  else
    return (0);
}

int             count_nb(char *str, int i)
{
  int           j;
  int           k;

  j = 0;
  k = 0;
  while (str[i])
    {
      if (str[i] == '+' || str[i] == '-' || str[i] == '%' ||
          str[i] == '*' || str[i] == '/')
        {
          j++;
          i = my_strlen(str) - 1;
        }
      i++;
      k++;
    }
  return (k - j);
}

char            **my_malloc(char **tab, int k, char *str)
{
  tab = malloc(sizeof(tab) * ((count_oper(str) + 1) * 2));
  tab[k] = malloc(sizeof(*tab) * count_oper(str));
  if (tab == NULL)
    exit (0);
  return (tab);
}

char            **my_str_to_wordtab(char *str)
{
  int           i;
  int           j;
  int           k;
  char          **tab;

  i = 0;
  j = 0;
  k = 0;
  tab = my_malloc(tab, k, str);
  while (str[i])
    {
      if (check_oper(str[i]) != 1 && is_num(str[i]) != 0)
        tab[j][k++] = str[i++];
      else if (check_oper(str[i]) == 1)
        {
          tab[j++][k] = '\0';
          tab[j] = malloc(sizeof(*tab));
          k = 0;
          tab[j][k++] = str[i++];
          tab[j++][k] = '\0';
          tab[j] = malloc(sizeof(*tab) * count_nb(str, i) + 1);
          k = 0;
        }
    }
  return (tab);
}
